#include <linux/init.h>
#include <linux/module.h>

#include <linux/kernel.h>
#include <linux/fs.h>
#include <mach/gpio.h>
#include <plat/gpio-cfg.h>
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
//#include <mach/gpio-bank.h>
#include <mach/regs-gpio.h>
#include <asm/io.h>
#include <linux/regulator/consumer.h>
//#include "gps.h"
#include <linux/delay.h>


#define DRIVER_NAME "leds"

//yt-02160325
static int led_gpios[] = {
	EXYNOS4_GPX2(7),
	EXYNOS4_GPX1(0),
	EXYNOS4_GPF3(4),
	EXYNOS4_GPF3(5),
};

#define LED_NUM		ARRAY_SIZE(led_gpios)

long leds_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
{
	printk("debug: leds_ioctl cmd is %d\n" , cmd);

	switch(cmd)
	{
		case 0:
		case 1:
			if (arg > LED_NUM) {
				return -EINVAL;
			}

			gpio_set_value(led_gpios[arg], cmd);
			break;

		default:
			return -EINVAL;
	}

	return 0;
}

static struct file_operations leds_ops = {
	.owner 	= THIS_MODULE,
	.unlocked_ioctl 	= leds_ioctl,
};

static struct miscdevice leds_dev = {
	.minor	= MISC_DYNAMIC_MINOR,
	.fops	= &leds_ops,
	.name	= "leds",
};


static int __init leds_init(void)
{
	int ret, i;
	char *banner = "leds Initialize\n";

	printk(banner);

	for(i=0; i<LED_NUM; i++)
	{
		ret = gpio_request(led_gpios[i], "LED");
		if (ret) {
			printk("%s: request GPIO %d for LED failed, ret = %d\n", DRIVER_NAME,
					led_gpios[i], ret);
			return ret;
		}

		s3c_gpio_cfgpin(led_gpios[i], S3C_GPIO_OUTPUT);
		gpio_set_value(led_gpios[i], 1);
	}

	ret = misc_register(&leds_dev);
	if(ret<0)
	{
		printk("leds:register device failed!\n");
		goto exit;
	}

	return 0;

exit:
	misc_deregister(&leds_dev);
	return ret;
}

static void __exit leds_exit(void)
{
	misc_deregister(&leds_dev);
}

module_init(leds_init);
module_exit(leds_exit);

MODULE_LICENSE("Dual BSD/GPL");
